package Day06;

import java.util.Random;
import java.util.Scanner;

public class exercise {
    public static void main(String[] args) {
        //定义say()无参无返回值方法，调用测试
        say();
        //定义say()有一个参无返回值方法，调用测试
        say("LJ");
        //定义say()有两个参无返回值的方法，调用测试
        say(21,"ChengDu");
        //定义sum()两个参有返回值方法，调用测试
        int sum=sum(5,6);
        System.out.println(sum);
        //定义generateArray()用于生成整型数组填充随机数并返回数组，调用测试
        int[] arr=generateArray(5,10);
        for (int i=0;i< arr.length;i++){
            System.out.println(arr[i]);
        }
        //需求:<<主持人大赛>>有N位评委给选手打分
        double[] scores=inputData(5);
        //选手的最终得分为:去掉最高分和最低分之后的N-2位评委的平均分
        double avg=calAvg(scores);
        System.out.println("平均分:"+avg);
        System.out.println("------------------");
        Scanner scan=new Scanner(System.in);
        Random rand=new Random();
        int num= rand.nextInt(100);
        System.out.println(num);
        while (true){
            System.out.println("猜吧");
            int a= scan.nextInt();
            if (a>num){
                System.out.println("猜大了");
            }else if(a<num){
                System.out.println("猜小了");
            }else {
                System.out.println("恭喜你猜对了!");
                break;
            }
        }
    }
    public static void say(){
        System.out.println("123");
    }
    public static void say(String name){
        System.out.println("大家好我叫"+name);
    }
    public static void say(int age,String from){
        System.out.println("我今年"+age+",我来自"+from);
    }
    public static int sum(int num1,int num2){
        int sum=num1+num2;
        return sum;
    }
    public static int[] generateArray(int len,int max){
        Random rand=new Random();
        int[] arr=new int[len];
        for (int i=0;i< arr.length;i++){
            arr[i]= rand.nextInt(max+1);
        }
        return arr;
    }
    public static double[] inputData(int n){
        double[] scores=new double[n];
        Scanner scan=new Scanner(System.in);
        for (int i=0;i< scores.length;i++){
            System.out.println("请录入第"+(i+1)+"位评委分数:");
            scores[i]=scan.nextDouble();
        }
        return scores;
    }
    public static double calAvg(double[] scores){
        double total=0.0;
        double max=scores[0];
        double min=scores[0];
        for (int i=0;i< scores.length;i++){
            total=total+scores[i];
            if (scores[i]>max){
                max=scores[i];
            }
            if (scores[i]<min){
                min=scores[i];
            }
        }
        double avg=(total-max-min)/(scores.length-2);
        return avg;
    }
}
